Skip to content

Jackknife uncertainty estimates for subspaceid - #215

Open
baggepinnen wants to merge 2 commits into
masterfrom
fb/subspace-uncertainty
Open

baggepinnen wants to merge 2 commits into
masterfrom
fb/subspace-uncertainty

Conversation

@baggepinnen

@baggepinnen baggepinnen commented Dec 2, 2026 •

Copy link
Copy Markdown
Member

Adds opt-in uncertainty estimation to the time-domain subspaceid, using the keyword convention of #214.

model, unc = subspaceid(d, nx; uncertainty = Val(:jackknife), nblocks = 10)
σmag = jackknife_std(s -> vec(abs.(freqresp(s, w))), unc) # std of |G(iω)|
σp   = pole_std(model, unc)                               # std of the poles, ordered as poles(model)
Σθ   = jackknife_cov(unc)                                 # covariance of [vec(A); vec(B); vec(C); vec(D); vec(K)]

Method

  • The columns of the data matrices [U; Φ; Y] correspond to time instants. They are partitioned into nblocks contiguous blocks, and A, C, K are re-estimated with one block of columns left out. B, D are re-estimated by the regression in find_BD restricted to the retained time instants (new optional argument keep).
  • The estimation from the data matrices is moved into the internal function subspace_core without changes to the computation, so that it can be applied to column subsets.
  • A realization is determined only up to a change of state basis. Each replicate is transformed to the state basis of the full-data model with T = Or_b \ Or, where Or and Or_b are the estimated extended observability matrices. Quantities that depend on the basis, such as the parameter covariance, are therefore expressed in the basis of the returned model.
  • The model order of the replicates is the order of the returned model, also for nx = :auto.
  • Val(false) (default) returns the model only, unchanged. The frequency-domain method throws an ArgumentError for any other value.

Fixes of existing behavior

  • find_PK divided the residual cross product by a constant determined by the matrix dimensions instead of by the number of data-matrix columns, so the estimated Q, R, S and P grew linearly with the record length (for a true R = 0.01: 0.10, 0.40, 1.60 at N = 1000, 4000, 16000; now 0.0124, 0.0120, 0.0120). K is unaffected, since the Riccati gain is invariant to a common scaling of Q, R, S.
  • stable = false was ignored; eigenvalue reflection of an unstable A was always applied. The default stable = true is unchanged.

Robustness

  • If the observable subspace of a replicate differs substantially from that of the full-data model (smallest principal-angle cosine below 0.5), the replicate is kept in its own state basis, a warning is issued, and unc.aligned records it. jackknife_cov(unc) then throws. Basis-invariant quantities (frequency response, poles) remain usable.
  • The blocks partition the whole record: samples before the first and after the last Hankel column start belong to the first and last block, respectively.
  • Weight matrices (e.g. TotalLeastSquares.wls with a Diagonal) are restricted to the retained principal submatrix.
  • pole_std assigns poles by minimum total distance (Hungarian algorithm).

Calibration

Monte Carlo comparison (fixed input, independent noise realizations, third-order system) of the RMS jackknife standard deviation with the standard deviation over realizations:

  • Approximately Gaussian regime (N = 8000, or N = 2000 at lower noise): ratio 0.9–1.25 for the frequency response and the poles.
  • Low data relative to noise (N = 2000, SNR lower): the estimator has heavier tails than a Gaussian distribution (std/MAD 1.3–1.7) and the jackknife overestimates by a factor of 1.3–1.9 for the frequency response and up to 4 for a weakly determined real pole. This is consistent with the upward bias of the jackknife variance for nonlinear statistics (Efron–Stein inequality). The documentation reports the observed calibration without claiming a guarantee.
  • The result is insensitive to nblocks in 5–20 and to the weighting W.

Other

  • Docs: new section "Uncertainty estimates" in ss.md with a magnitude plot with ±2σ band and pole standard deviations.
  • Tests: noise-covariance normalization, stable = false, partition of the record, weight matrices, pole assignment against brute force, detection of unaligned replicates, equality with the default estimate, alignment of the replicates, Val(true), nx = :auto, all W, zeroD, focus = :simulation, scaleU = false, weights, MIMO, error cases, and a Monte Carlo calibration check (100 realizations).

The output type of subspaceid is not inferred, either with or without this change (find_PK returns P = I(n) in its fallback branch), so no inference test is added.


Host: demeter2 · Session: f206e1d5-e03e-456f-aba8-1778b9dede55 · Working dir: ~/repos/CSI-subspace

🤖 Generated with Claude Code

baggepinnen and others added 2 commits December 2, 2026 21:21
subspaceid(data, nx; uncertainty = Val(:jackknife), nblocks) returns the
model together with a SubspaceJackknife object holding one estimate per
left-out block of data matrix columns, transformed to the state basis of
the full-data model through the extended observability matrix.
jackknife_std, jackknife_cov and pole_std compute standard deviations and
covariances from these replicates.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
- Normalize the residual covariance in find_PK by the number of data matrix
  columns; Q, R, S and P previously grew linearly with the record length.
- Honor stable = false (eigenvalue reflection was applied unconditionally).
- Assign the samples before the first and after the last Hankel column to
  the first and last block, so that the blocks partition the record.
- Detect replicates whose observable subspace differs from the full-data
  model (smallest principal-angle cosine below 0.5), keep them in their own
  basis, warn, and record this in SubspaceJackknife.aligned;
  jackknife_cov(unc) throws in that case.
- Support covariance-type weight matrices in the B/D regression.
- Match poles by minimum total distance (Hungarian algorithm).
- State the observed calibration in the documentation.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant